package com.example.sunsg.okhttptest.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.breadtrip.R;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;


public class EventBusActivity extends AppCompatActivity {
    private String name;
    private Button mBtn;

    public EventBusActivity() {
    }

    public static void launch(Context context){
        context.startActivity(new Intent(context, EventBusActivity.class));
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_event_bus);
        Button btn = (Button) findViewById(R.id.btn_send);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                EventBus.getDefault().post(new EventMessage("title","content"));
                EventBusSecondActivity.SecondMessage message = new EventBusSecondActivity.SecondMessage("title","content");
                Log.i("test","message.tostring = "+message.toString());
                EventBus.getDefault().postSticky(message);
                EventBus.getDefault().postSticky("sdjflkjdslkflds");
                EventBus.getDefault().post("");
            }
        });

        Button jump = (Button) findViewById(R.id.btn_jump);
        jump.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                EventBusSecondActivity.launch(EventBusActivity.this);
            }
        });
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void eventMessage(EventMessage eventMessage){
        Log.i("test","eventmessage.title = "+eventMessage.getTitle() +" eventmessage.content = "+ eventMessage.getContent());
    }
    public static class EventMessage{
        private String title;
        private String content;

        public EventMessage() {
        }

        public EventMessage(String title, String content) {
            this.title = title;
            this.content = content;
        }

        public String getTitle() {
            return title;
        }

        public void setTitle(String title) {
            this.title = title;
        }

        public String getContent() {
            return content;
        }

        public void setContent(String content) {
            this.content = content;
        }
    }

}
